import requests
from lxml import etree
def changeme(pagenum):
   url = 'https://www.amazon.com/hz/leaderboard/top-reviewers/ref=cm_cr_tr_link_2?page=%d'%(pagenum)
   head = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
   proxy_id = { "http": "http://58.32.15.247:443"}
   cookie = {'session-id':'459-4568418-5692641','ubid-acbcn':'459-5049899-3055220','x-wl-uid':'1AK7YMFc9IzusayDn2fT6Topjz3iAOpR3EeA2UQSqco8fo5PbK2aCpyBA/fdPMfKFqZRHc4IeyuU=','session-token':'OH1wPvfOj6Tylq2nnJcdn5wyxycR/lqyGsGU3+lUtU4mbC0ZD9s8/4Oihd1BlskUQG8zRbLVs9vfWXuiJmnRlDT4x35ircp2uLxOLNYQ4j5pzdFJIqqoZUnhHSJUq2yK80P3LqH8An7faXRCPW9BIqX1wu0WmHlSS9vYAPKA/2SGdV9b//EljYjIVCBjOuR/dKRiYEeGK3li0RJOVz7+vMWg7Rnzbx89QxlbCp0WyquZyVxG6f2mNw=="','session-id-time':'2082787201l'}
   r = requests.get(url,headers=head,proxies=proxy_id,cookies=cookie)
   r.encoding = r.apparent_encoding
   print(r.text)
   html = etree.HTML(r.text)
   result = html.xpath('//tr/td[3]/a[1]/@href')
   while (len(result)>10):
    del result[10]
   for line in result:
    f.write('https://www.amazon.com'+line+'\n')
   print(len(result))
for num in range(1,1001):
   f=open("mk.txt","a",encoding="utf-8")
   print(num)
   changeme(num)
   f.close()
print('保存成功')